import 'package:fish_redux/fish_redux.dart';
import '../../../app_files.dart';
import 'dart:convert' as convert;
import '../../MainView/model/main_view_model.dart';

class FixResultViewState implements Cloneable<FixResultViewState> {
  bool isDetail = false;
  FixResultModel model = FixResultModel(orderPhoto: []);
  bool isLoad = false;
  FixListItemModel itemModel;
  String problemContent = '';
  List logList =[];

  @override
  FixResultViewState clone() {
    return FixResultViewState()
      ..isDetail = isDetail
      ..itemModel = itemModel
      ..logList = logList
      ..problemContent = problemContent
      ..isLoad = isLoad
      ..model = model;
  }
}

FixResultViewState initState(Map<String, dynamic> args) {
  FixResultViewState state = FixResultViewState()
    ..isDetail = args['isDetail']
    ..itemModel = args['model'];
  if (!state.isDetail) {
    state.model.repairContent = args['repairContent'];
    state.model.repairPhotos = args['repairPhotos'];
  }
  return state;
}

class FixResultModel {
  var signPhoto;
  var orderPhoto;
  bool isSolve;
  String repairContent;
  List repairPhotos;
  String beforeContent;
  List beforePhotos;

  FixResultModel({
    this.signPhoto,
    this.orderPhoto,
    this.isSolve,
    this.repairPhotos,
    this.repairContent,
    this.beforeContent,
    this.beforePhotos,
  });

  static fromJson(json) {
    String jsonContent =
        CommonUtils.checkNullToString(json['bizMaintenanceremark']);
    print(jsonContent);
    Map info = convert.jsonDecode(jsonContent);
    List<String> orderPhoto =
        CommonUtils.checkNullToString(json['bizMaintenancefiles']).isEmpty
            ? []
            : CommonUtils.checkNullToString(json['bizMaintenancefiles'])
                .split(',');
    return FixResultModel(
        signPhoto: CommonUtils.checkNullToString(json['bizSignature']),
        orderPhoto: orderPhoto,
        isSolve: CommonUtils.checkNullToString(json['bizResult']) == '1',
        repairContent: info['RepairContent'],
        repairPhotos: info['RepairPhotos'],
        beforeContent: info['BeforeContent'] ?? '',
        beforePhotos: info['BeforePhotos'] ?? []);
  }
}
